<?php	
	$db = new MySQL();   
	$table = "tip";
	$id = $_GET['id'];	
	$mod = $_GET['mod'];
	
	$titlemenu = (isset($_POST["titlemenu"]))?$_POST["titlemenu"]:"";
		$titlemenu = str_replace("'", "\\'", $titlemenu);
		$titlemenu = str_replace("\\\'", "\\'", $titlemenu);
	
	$titlemenu_vn = (isset($_POST["titlemenu_vn"]))?$_POST["titlemenu_vn"]:"";
		$titlemenu_vn = str_replace("'", "\\'", $titlemenu_vn);
		$titlemenu_vn = str_replace("\\\'", "\\'", $titlemenu_vn);
	
	$content = (isset($_POST["content"]))?$_POST["content"]:"";
		$content = str_replace("'", "\\'", $content);
		$content = str_replace("\\\'", "\\'", $content);
	
	$content_vn = (isset($_POST["content_vn"]))?$_POST["content_vn"]:"";
		$content_vn = str_replace("'", "\\'", $content_vn);
		$content_vn = str_replace("\\\'", "\\'", $content_vn);

	
	$titlepage = (isset($_POST["titlepage"]))?$_POST["titlepage"]:"";
		$titlepage = str_replace("'", "\\'", $titlepage);
		$titlepage = str_replace("\\\'", "\\'", $titlepage);
	
	$meta_key = (isset($_POST["meta_key"]))?$_POST["meta_key"]:"";	
		$meta_key = str_replace("'", "\\'", $meta_key);
		$meta_key = str_replace("\\\'", "\\'", $meta_key);
	$meta_des = (isset($_POST["meta_des"]))?$_POST["meta_des"]:"";	
		$meta_des = str_replace("'", "\\'", $meta_des);
		$meta_des = str_replace("\\\'", "\\'", $meta_des);	
		
	
	if ($_POST["form_"]=="edit")
	{
		if(isset($_GET['id']))
		{
			$query_image = "select * from $table where id='$id'";
			$sql_image = $db->select($query_image);
			$tt_image = $db->fetch($sql_image);				
			$image  = $tt_image['image'];	
		}
		
		//image
		if ($_FILES['image']['name'] != "")	
		{				
						
			$parts1=pathinfo($_FILES['image']['name']);
			$ext1=".".strtolower($parts1["extension"]);																			

			
			if (file_exists("../news-img/".$_FILES["image"]["name"]))
			{
				$attach_file = date("sihdmy").$ext1;
			}
			else 
			{											  
				$attach_file = str_replace(" ","_",$_FILES["image"]["name"]);
			}
			
			if(move_uploaded_file($_FILES["image"]["tmp_name"], "../news-img/".$attach_file))
			{	
				$filemod = "../news-img/".$attach_file;
				
				chmod($filemod,0777);
				
				resize_jpg($filemod,$filemod,330,0);
				
				
				if($image !="" && file_exists("../news-img/".$image))   
				{
					unlink("../news-img/".$image); 					
				}	
				$image = $attach_file;
			}					
		}				
		//cap nhat du lieu
		$query="update $table set titlemenu = '$titlemenu', titlemenu_vn = '$titlemenu_vn', content = '$content', content_vn = '$content_vn', image = '$image', titlepage = '$titlepage',  meta_key = '$meta_key', meta_des = '$meta_des' ";
		$query.=" where id='$id'";
		$sql = $db->update($query);								
		$db->close();							
		echo "<script>location='?mod=".$mod."&act=edit&id=".$id."'</script>";	
	}	
		

?>
